package controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import serice.Goodsserivice;
import entity.Criteria;
import entity.Goods;
import entity.UserFootCriteria;
import entity.UserFootGoods;
import entity.ajaxResult;


@Controller
public class Goodscontroller {
	@Autowired
	private Goodsserivice servceimpl;
	
	@RequestMapping("findGoodsByCriteria")
	@ResponseBody
	public List<Goods> findGoodsByCriteria(@RequestParam(defaultValue="1") Integer page,
											Integer gid,
											String gname,
											@RequestParam(defaultValue="1")Integer gtype){
		Criteria cr=new Criteria();
		Integer start=(page-1)*4;
		Integer offset=4;
		cr.setOffset(offset);
		cr.setStart(start);
		cr.setGname(gname);
		cr.setGid(gid);
		cr.setGtype(gtype);
		List<Goods> list=servceimpl.findGoodsByCriteria(cr);
		return list;
	}
	
	
	
	
	
	
	@RequestMapping("findGoodsTypeList")
	@ResponseBody
	public ajaxResult<Goods> findGoodsTypeList(@RequestParam(defaultValue="1")Integer page, 
										 @RequestParam(defaultValue="1")Integer gtype){
		Integer start=(page-1)*10;
		Integer offset=10;
		Criteria cr=new Criteria();
		cr.setGtype(gtype);
		cr.setStart(start);
		cr.setOffset(offset);
		List<Goods> list=servceimpl.findGoodsByCriteria(cr);
		Integer count=servceimpl.getCount();
		ajaxResult<Goods> ajax=new ajaxResult<Goods>();
		ajax.setList(list);
		ajax.setCount(count);
		return ajax;
	}

	@RequestMapping("getUserFoot")
	@ResponseBody
	public ajaxResult<UserFootGoods> getUserFoot(Integer uid,@RequestParam(defaultValue="1") Integer page){
		Integer start=(page-1)*5;
		Integer offset=5;
		UserFootCriteria cr=new UserFootCriteria();
		cr.setUid(uid);
		cr.setStart(start);
		cr.setOffset(offset);
		List<UserFootGoods> list=servceimpl.selectUserFoot(cr);
		ajaxResult<UserFootGoods> ajax=new ajaxResult<UserFootGoods>();
		ajax.setList(list);
		ajax.setCount(list.size());
		ajax.setMsg("success");
		return ajax;
	}
}
